home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / glibc108.zip / glibc108 / manual / examples / isockad.c < prev    next >
C/C++ Source or Header  |  1994-02-16  |  529b  |  24 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/socket.h>
  4. #include <netinet/in.h>
  5. #include <netdb.h>
  6.  
  7. void 
  8. init_sockaddr (struct sockaddr_in *name,
  9.            const char *hostname,
  10.            unsigned short int port)
  11. {
  12.   struct hostent *hostinfo;
  13.  
  14.   name->sin_family = AF_INET;
  15.   name->sin_port = htons (port);
  16.   hostinfo = gethostbyname (hostname);
  17.   if (hostinfo == NULL) 
  18.     {
  19.       fprintf (stderr, "Unknown host %s.\n", hostname);
  20.       exit (EXIT_FAILURE);
  21.     }
  22.   name->sin_addr = *(struct in_addr *) hostinfo->h_addr;
  23. }
  24.